﻿using JoinBoxAlignPlug;
using JoinBoxAlignPlug.修改文本;
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace ConsoleApp1
{
    public class Program
    {
        static void Main(string[] args)
        {
            string path = @"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC#\Snippets\2052\Visual C#";
            //var dir = new DirectoryInfo(path);
            //var dirSub = dir.GetFiles("*.snippet", SearchOption.TopDirectoryOnly);
            //foreach (var item in dirSub)
            //{
            //    var str = SnippetHelper.GetSnippetFileInsertString(item.FullName);
            //    Console.WriteLine(str);
            //}

            path += @"\foreach.snippet";
            //var aaa = ObjectToXmlDESerializer<JoinBoxAlignPlug.SnippetHelper.CodeSnippets>(item.FullName);

            var xmlDoc = new XmlDocument();
            xmlDoc.Load(path);
            var snippet = new SnippetXmlCodes(xmlDoc);
        }

        //xml反序列化
        public static T ObjectToXmlDESerializer<T>(string str) where T : class
        {
            object obj;
            using (var mem = new MemoryStream(Encoding.Default.GetBytes(str)))
            {
                using (var reader = XmlReader.Create(mem))
                {
                    var formatter = new XmlSerializer(typeof(T));
                    obj = formatter.Deserialize(reader);
                }
            }
            return obj as T;
        }


        static void Main1(string[] args)
        {
            var path = @"..\..\..\..\测试工程\ClassLibrary1\调整对齐测试用.cs";
            // path = @"..\..\..\..\测试工程\ClassLibrary1\调整对齐测试用2.cs";
            path = Path.GetFullPath(path);

            // 这里没有先格式化,所以只能先在vs上面格式化了再调试

            string str1 = File.ReadAllText(path);
            var cta = new ChangTextAlignment(str1, EncodingHelper.Read(path));
            cta.TextTrimEnd();
            cta.TextAlignment("=");
            cta.TextAlignment("//");
            File.WriteAllText(path, cta.ToString());

            Console.ReadKey();
        }
    }
}
